<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>采购订单记录</title>
    <script type="text/javascript">
      var newPurchaseOrderWin;
      var editPurchaseOrderWin;
      var newPurchaseReturnedWin;
      
      var purchaseOrderId;
      var entryForPurchaseWin;
      var paymentListWin;
      var currentOrderNumber;//当前正操作的采购单单号
      Ext.onReady(function(){
        var vendorTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{name}', '</div></tpl>');
        var vendorStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/vendor/getAllVendors?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            }, {
              name: 'name'
            }])
        });

        var vendor =  new Ext.form.ComboBox({
          fieldLabel: '供应商',
          store: vendorStore,
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'vendor_id',
          //typeAhead: false,
          loadingText: '搜索中...',
          //pageSize: 10,
          //hideTrigger: false,
          tpl: vendorTemplate,
          minChars: 0,
          itemSelector: 'div.search-item',
          triggerAction: 'all',
          editable:false,
          anchor: '95%',
          selectOnFocus:true
        });
        
        var purchaseOrderNumber = new Ext.form.TextField({
          fieldLabel: '采购单号',
          anchor: '95%',
          name: 'purchase_order_number'
        });

        var saleOrderNumber = new Ext.form.TextField({
          fieldLabel: '销售单号',
          anchor: '95%',
          name: 'sale_order_number'
        });

        var stateStore = new Ext.data.ArrayStore({
          fields: ['text','value'],
          data : auditStatusArray
        });
        
        var auditingStatus = new Ext.form.ComboBox({
          fieldLabel: '审批状态',
          store: stateStore,
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          name: 'auditing_status',
          forceSelection: true,
          triggerAction: 'all',
          editable:false,
          valueField: 'value',
          emptyText:'',
          anchor: '95%',
          selectOnFocus:true
        })

        var productTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">','<div style="float:left; width:220px">{name}</div><div style="float:left; width:90px">{number}</div>{is_suit}','</div></tpl>');
        productTemplate.compile();
        var productStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/product/getAllProducts?for_cbb=true_simple"
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            }, {
              name: 'name'
            }, {
              name: 'is_suit',
              mapping:'is_suit',
              convert:function(value,record){
                if(value == "1"){
                  return "套装";
                }else if(value == "0"){
                  return "单品";
                }
              }
            }])
        });
        //产品
        var productCBB = new Ext.form.ComboBox({
          store: productStore,
          fieldLabel: '产品',
          emptyText: '请选择...',
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'product_id',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '100%',
          pageSize: 25,
          //hideTrigger: false,
          tpl: productTemplate,
          minChars: 0,
          itemSelector: 'div.search-item',
          triggerAction: 'all',
          selectOnFocus:true
        });
        
        var beginDate = new Ext.form.DateField({
          fieldLabel: '到货日期',
          name: 'begin_date',
          id: 'begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          inputType: '2010-01-01',
          anchor: '100%',
          vtype: 'daterange',
          endDateField: 'end_date'
        });
        
        var endDate = new Ext.form.DateField({
          fieldLabel: '至',
          name: 'end_date',
          id: 'end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          inputType: '2010-01-01',
          anchor: '100%',
          vtype: 'daterange',
          startDateField: 'begin_date'
        });

        var employeeTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{name}</div>', '</div></tpl>');
        var employeeStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/employee/getAllEmployees?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            }, {
              name: 'name'
            }])
        });

        //制单员
        var employeeCBB = new Ext.form.ComboBox({
          store: employeeStore,
          fieldLabel: '制单员',
          emptyText: '请选择...',
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'employee_id',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '100%',
          //pageSize: 10,
          triggerAction: 'all',
          tpl: employeeTemplate,
          minChars: 0,
          itemSelector: 'div.search-item',
          selectOnFocus:true
        });

        var cBeginDate = new Ext.form.DateField({
          fieldLabel: '制单日期',
          name: 'c_begin_date',
          id: 'c_begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          inputType: '2010-01-01',
          anchor: '100%',
          vtype: 'daterange',
          endDateField: 'c_end_date'
        });

        var cEndDate = new Ext.form.DateField({
          fieldLabel: '至',
          name: 'c_end_date',
          id: 'c_end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          inputType: '2010-01-01',
          anchor: '100%',
          vtype: 'daterange',
          startDateField: 'c_begin_date'
        });
        
        var submitButton = new Ext.Button({
          text: '搜索',
          iconCls: 'finding',
          handler: function(){
            purchaseOrderDS.removeAll();
            purchaseOrderDS.baseParams.purchase_order_number = purchaseOrderNumber.getValue();
            purchaseOrderDS.baseParams.sale_order_number = saleOrderNumber.getValue();
            purchaseOrderDS.baseParams.auditing_status = auditingStatus.getValue();

            purchaseOrderDS.baseParams.begin_date = beginDate.getRawValue();
            purchaseOrderDS.baseParams.end_date = endDate.getRawValue();
            purchaseOrderDS.baseParams.vendor_id = vendor.getValue();
            purchaseOrderDS.baseParams.product_id = productCBB.getValue();
            purchaseOrderDS.baseParams.employee_id = employeeCBB.getValue();
            purchaseOrderDS.baseParams.c_begin_date = cBeginDate.getRawValue();
            purchaseOrderDS.baseParams.c_end_date = cEndDate.getRawValue();
            
            purchaseOrderDS.load();
          }
        });

        var clearButton = new Ext.Button({
          text: '清空',
          width:50,
          handler: function(){ 
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = new Ext.form.FormPanel({
          //baseCls: 'x-plain',
          //renderTo: 'query_form',
          labelWidth: 55,
          width: screenWidth-175,
          labelAlign: 'right',
          buttonAlign: 'center',
          frame : true,
          border:false,
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1200},
              title: '查询条件',
              border: true,              
              items: [{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: .12,
                      layout: 'form',
                      border: false,
                      items: [purchaseOrderNumber]
                    }, {
                      columnWidth: .125,
                      layout: 'form',
                      border: false,
                      items: [cBeginDate]
                    }, {
                      columnWidth: .11,
                      layout: 'form',
                      border: false,
                      labelWidth: 30,
                      items: [cEndDate]
                    }, {
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [vendor]
                    }, {
                      columnWidth: .34,
                      layout: 'form',
                      border: false,
                      labelWidth: 40,
                      items: [productCBB]
                    }]
                },{
                  layout: 'column',
                  border: false,                  
                  items: [{
                      columnWidth: .12,
                      layout: 'form',
                      border: false,
                      items: [saleOrderNumber]
                    },{
                      columnWidth: .125,
                      layout: 'form',
                      border: false,
                      items: [beginDate]
                    }, {
                      columnWidth: .11,
                      layout: 'form',
                      border: false,
                      labelWidth: 30,
                      items: [endDate]
                    }, {
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [auditingStatus]
                    }, {
                      columnWidth: .12,
                      layout: 'form',
                      border: false,
                      labelWidth: 40,
                      items: [employeeCBB]
                    }, {
                      columnWidth: .11,
                      layout: 'form',
                      border: false,
                      items: [submitButton]
                    }, {
                      columnWidth: .11,
                      layout: 'form',
                      border: false,
                      items: [clearButton]
                    }]
                }]
            }]
        });
        //显示采购订单操作时的窗口介面。
        //----------------------------------采购订单Grid-------------------------
        //采购订单Grid Store
        var purchaseOrderDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: pageSize
          },
          proxy: new Ext.data.HttpProxy({
            url: '/purchase_order/getAllPurchaseOrders'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'order_number'
            }, {
              name: 'action_date'
            }, {
              name: 'amount',
              type: 'float'
            }, {
              name: 'tax_price'
            }, {
              name: 'tax_amount',
              type: 'float'
            }, {
              name: 'value_added_tax',
              type: 'float'
            }, {
              name: 'paid_amount',
              type: 'float'
            }, {
              name: 'description'
            }, {
              name: 'auditing_status'
            }, {
              name: 'audit_opinion'
            },{
              name: 'auditor_name',
              mapping:'auditor',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            }, {
              name: 'vendor_name',
              mapping:'vendor.name'
            }, {
              name: 'department_name',
              mapping:'department.name'
            }, {
              name: 'employee_name',
              mapping:'employee.name'
            }, {
              name: 'deal_with_status'
            }, {
              name: 'store_status'
            }, {
              name: 'delivery_employee_name',
              mapping: 'delivery_employee',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }])
        });
        
        //生成采购订单Grid的CM
        var purchaseOrderSM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        var purchaseOrderCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),
            purchaseOrderSM,{
              id: 'common',
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '采购订单单号',
              dataIndex: 'order_number',
              width: 120
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 130
            },{
              header: '总金额',
              dataIndex: 'amount',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 85
            },{
              header: '进项税',
              dataIndex: 'value_added_tax',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 85
            },{
              header: '总金额(含税)',
              dataIndex: 'tax_amount',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 100
            },{
              header: '已付金额',
              dataIndex: 'paid_amount',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              align: 'right',
              width: 75
            },{
              header: '到货日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),
              width: 75
            },{
              header: '操作员',
              dataIndex: 'employee_name',
              width: 60
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              width: 60,
              renderer: auditingStatusRender
            },{
              header: '审批者',
              dataIndex: 'auditor_name',
              width: 55
            },{
              header: '审批意见',
              dataIndex: 'audit_opinion',
              width: 150
            },{
              header: '处理状态',
              dataIndex: 'deal_with_status',
              renderer: dealWithStatusRender,
              width: 70
            },{
              header: '入库状态',
              dataIndex: 'store_status',
              renderer: dealWithStatusRender,
              width: 70
            },{
              header: '仓库操作员',
              dataIndex: 'delivery_employee_name',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 190
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 110
            },{
              header: '修改日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 110
            }
          ]});

        //生成要订单的产品的Grid
        var purchaseOrderGrid = new Ext.grid.GridPanel({
          title:'采购订单列表',
          store: purchaseOrderDS,
          cm: purchaseOrderCM,
          sm: purchaseOrderSM,
          loadMask: true,
          width: screenWidth-175,
          height: 345,
          frame: true,
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
          bbar: new Ext.PagingToolbar({
            pageSize: pageSize,
            store: purchaseOrderDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          }),
          tbar: [{
              text: '新增',
              iconCls: 'addItem',
              handler : function(){
                newPurchaseOrderWin = new Ext.Window({
                  layout: 'fit',
                  width: 1260,
                  height: 505,
                  closeAction: 'destroy',
                  plain: true,
                  modal: true,
                  constrain:true,
                  //modal: true,
                  title: '新增采购订单',
                  autoLoad: {
                    url: "/purchase_order/newPurchaseOrder",
                    scripts: true,
                    callback: function(options, success, response, request)
                    { 
                      if (response.responseText === "NoPrivilege"){
                        newPurchaseOrderWin.close();
                      }
                    }
                  }
                });
                newPurchaseOrderWin.on("destroy",function(){
                  purchaseOrderDS.reload();
                });
                newPurchaseOrderWin.resizable = false;
                newPurchaseOrderWin.show();
              }
            },"-",{
              text: '编辑',
              iconCls: 'editItem',
              handler : function(){
                var records = purchaseOrderGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.show({
                    title: '提示信息',
                    msg: "请先选中一条记录后，再编辑。",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }else{
                  purchaseOrderId = records[0].get('id');
                  if(records[0].get('auditing_status') != '通过' && records[0].get('auditing_status').indexOf('申请') < 0 && records[0].get('deal_with_status') != '撤消'){
                    editPurchaseOrderWin = new Ext.Window({
                      layout: 'fit',
                      width: 1260,
                      height: 505,
                      closeAction: 'destroy',
                      plain: true,
                      modal: true,
                      constrain:true,
                      //modal: true,
                      title: '编辑采购订单',
                      autoLoad: {
                        url: "/purchase_order/editPurchaseOrder?id="+purchaseOrderId,
                        scripts: true,
                        callback: function(options, success, response, request)
                        {
                          if (response.responseText === "NoPrivilege"){
                            editPurchaseOrderWin.close();
                          }
                        }
                      }
                    });
                    editPurchaseOrderWin.on("destroy",function(){
                      purchaseOrderDS.reload();
                    });
                    editPurchaseOrderWin.resizable = false;
                    editPurchaseOrderWin.show();
                  }else{
                    Ext.Msg.alert('提示信息','正在申请、已经通过审批或已经撤消的采购订单，不能编辑。');
                  }
                } 
              }
            },"-",{
              text: '撤消',
              iconCls: 'cancel',
              handler : function(){
                var records = purchaseOrderGrid.getSelectionModel().getSelections();
                if (records.length == 0) {
                  return false;
                }else{
                  if(records[0].get('auditing_status').indexOf('申请') < 0 && records[0].get('auditing_status').indexOf('撤消') < 0 ){
                    var orderNumber = records[0].get('order_number')
                    purchaseOrderId = records[0].get('id');
                    Ext.MessageBox.confirm("提示","你确认要申请撤消订单号为： \""+orderNumber+"\" 的采购订单吗？",function(btn){
                      if(btn=="yes"){
                        Ext.Ajax.request({
                          url : '/purchase_order/applyToCancel?id=' + purchaseOrderId,
                          success : function (result, request) {
                            purchaseOrderDS.reload();
                          },
                          failure : function (result, request){
                            Ext.MessageBox.show({
                              title: '消息',
                              msg: "通讯失败，请从新操作",
                              buttons: Ext.MessageBox.OK,
                              icon: Ext.MessageBox.WARNING
                            });
                          },
                          method : 'GET'
                        });
                      }else{
                        //alert("no");
                      }
                    });
                  }else{
                    Ext.Msg.alert('提示信息','正处于申请状态或已经撤消的订单，不能撤消。');
                  }
                }
              }
            },'-',{
              text: '打印采购凭据',
              iconCls: 'print',
              handler : function(){
                this.disable();
                var records = purchaseOrderGrid.getSelectionModel().getSelections();
                purchaseOrderId = records[0].get('id');
                employeeName = records[0].get('employee_name');
                //LODOP.SET_PRINT_PAGESIZE(1,0,0,'A5')
                //LODOP.SET_PRINT_PAGESIZE(1,'297mm','210mm',"");
                //LODOP.SET_PRINT_PAGESIZE(3,'297mm','210mm',"");
                LODOP.PRINT_INIT("");
                LODOP.SET_PRINT_PAGESIZE(2,0,0,"A4");
                //LODOP.SET_PRINT_PAGESIZE(1,"148mm","210mm","")
                LODOP.ADD_PRINT_URL(30,'5%',"90%","100%",'http://'+window.location.host+'/purchase_order/purchase_order_print_header?id='+purchaseOrderId);
                LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                LODOP.ADD_PRINT_TBURL(220,'5%',"95%","55%",'http://'+window.location.host+'/purchase_order/purchase_order_print_content?id='+purchaseOrderId);
                LODOP.SET_PRINT_STYLEA(0,"ItemType",4);
                LODOP.ADD_PRINT_HTM(670,'15%',"90%","8%","<div style='font-size:16px'>制单人："+employeeName+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;打印日期："+getDate()+"</div>");
                LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                LODOP.ADD_PRINT_TEXT(687,"60.34%","17.36%","3.9%","页号：第#页/共&页");
                LODOP.SET_PRINT_STYLEA(0,"FontName","宋体");
                LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                LODOP.SET_PRINT_STYLEA(0,"ItemType",2);       
                LODOP.PREVIEW();
                //LODOP.PRINT_DESIGN();
                this.enable();
              }
            }]
        });
        
        //purchaseOrderDS.load(privilegeJsonCallBack);
        purchaseOrderDS.load();
        
        purchaseOrderGrid.on('rowdblclick', function(gridPanel, rowIndex, e){
          purchaseOrderId = purchaseOrderDS.getAt(rowIndex).get('id');
          var purchaseOrderNumber = purchaseOrderDS.getAt(rowIndex).get('order_number');
          //purchaseOrderDS.reload();
          purchaseOrderDetailDS.removeAll();
          purchaseOrderDetailDS.baseParams.purchase_order_id = purchaseOrderId;
          purchaseOrderDetailDS.load();
          purchaseOrderDetailGrid.setTitle("采购订单："+purchaseOrderNumber+"，的详细信息");
        });
        
        //右键菜单，以弹出此订单相关的入库单
        //右键
        purchaseOrderGrid.on('rowcontextmenu', function(grid, rowIndex, e){
          purchaseOrderId = purchaseOrderDS.getAt(rowIndex).get('id');
          currentOrderNumber = purchaseOrderDS.getAt(rowIndex).get('order_number');
          var auditingStatus = purchaseOrderDS.getAt(rowIndex).get('auditing_status');
          returnedItem.setDisabled(true);
          if (auditingStatus.indexOf("撤消") < 0){
            returnedItem.setDisabled(false);
          }
          if (auditingStatus.indexOf("通过") > -1){
            entriesForPurchaseItem.setDisabled(false);
          }else {
            entriesForPurchaseItem.setDisabled(true);
          }
          e.preventDefault();
          rightClick.showAt(e.getXY());
        });
        //############ 订单-右键菜单 ##########
        var entriesForPurchaseItem = new Ext.menu.Item({
          text: '【相关入库单信息】',
          //iconCls: 'album',
          handler: rightMenuEntriesForPurchaseFn
        });

        function rightMenuEntriesForPurchaseFn(){
          entryForPurchaseWin = new Ext.Window({
            layout: 'fit',
            width:998,
            height: 575,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            draggable: false,
            //modal: true,
            title: '采购订单\"'+currentOrderNumber+'\"相关的入库单信息',
            autoLoad: {
              url: "/purchase_order/entryForPurchaseList?id="+purchaseOrderId,
              scripts: true
            }
          });
          entryForPurchaseWin.on("destroy",function(){
            purchaseOrderDS.reload();
          });
          entryForPurchaseWin.resizable = false;
          entryForPurchaseWin.show();
        }

        var paymentItem = new Ext.menu.Item({
          text: '【付款记录】',
          //iconCls: 'album',
          handler: rightMenuPaymentFn
        });

        function rightMenuPaymentFn(){
          paymentListWin = new Ext.Window({
            layout: 'fit',
            width: 1000,
            height: 275,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            draggable: false,
            //modal: true,
            title: '采购订单：\"'+currentOrderNumber+'\"的付款记录',
            autoLoad: {
              url: "/purchase_order/payablesListForPurchase?id="+purchaseOrderId,
              scripts: true
            }
          });
          paymentListWin.on("destroy",function(){
            purchaseOrderDS.reload();
          });
          paymentListWin.resizable = false;
          paymentListWin.show();
        }

        var returnedItem = new Ext.menu.Item({
          text: '【采购退货】',
          //iconCls: 'album',
          handler: rightMenuReturnedFn
        });

        function rightMenuReturnedFn(){
          newPurchaseReturnedWin = new Ext.Window({
            layout: 'fit',
            width: 1160,
            height: 500,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            draggable: false,
            //modal: true,
            title: '采购订单：\"'+currentOrderNumber+'\"的退货记录',
            autoLoad: {
              url: "/purchase_returned/newPurchaseReturned?id="+purchaseOrderId,
              scripts: true
            }
          });
          newPurchaseReturnedWin.on("destroy",function(){
            purchaseOrderDS.reload();
          });
          newPurchaseReturnedWin.resizable = false;
          newPurchaseReturnedWin.show();
        }

        var purchaseOrderHxItem = new Ext.menu.Item({
          text: '【变更历史】',
          //iconCls: 'album',
          handler: rightMenuPurchaseOrderHxFn
        });

        function rightMenuPurchaseOrderHxFn(){
          purchaseOrderHxWin = new Ext.Window({
            layout: 'fit',
            width: 960,
            height: 550,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            draggable: false,
            //modal: true,
            title: '采购订单：\"'+currentOrderNumber+'\"的变更记录',
            autoLoad: {
              url: "/purchase_order/hxListForPurchase?id="+purchaseOrderId,
              scripts: true
            }
          });
          purchaseOrderHxWin.on("destroy",function(){
            purchaseOrderDS.reload();
          });
          purchaseOrderHxWin.resizable = false;
          purchaseOrderHxWin.show();
        }
        
        var rightClick = new Ext.menu.Menu({
          items: [entriesForPurchaseItem,paymentItem,'-',returnedItem,'-',purchaseOrderHxItem]
        });


        //--------------------------采购订单详细，双击后可显示数据----------------
        //采购订单Grid Store Detail
        var purchaseOrderDetailDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/purchase_order/getPurchaseOrderDetailsBalanceById'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'sale_order_number'
            },{
              name: 'sale_order_status'
            },{
              name: 'product_name'
            },{
              name: 'product_number'
            },{
              name: 'spec'
            },{
              name: 'quantity',
              type: 'int'
            }, {
              name: 'unit_price',
              type: 'float'
            }, {
              name: 'amount',
              type: 'float'
            }, {
              name: 'tax_price',
              type: 'float'
            }, {
              name: 'tax_amount',
              type: 'float'
            }, {
              name: 'value_added_tax',
              type: 'float'
            }, {
              name: 'is_suit',
              convert:function(value,record){
                if(value == "1"){
                  return "套装";
                }else if(value == "0"){
                  return "单品";
                }
              }
            },{
              name: 'balance_quantity'
            }, {
              name: 'description'
            }])
        });

        //生成采购订单详细表的Grid的CM
        var purchaseOrderDetailSM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        var purchaseOrderDetailCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),purchaseOrderDetailSM,{
              id: 'common',
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '销售订单单号',
              dataIndex: 'sale_order_number',
              width: 210
            },{
              header: '销售审批状态',
              dataIndex: 'sale_order_status',
              renderer: auditingStatusRender,
              width: 100
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '编号',
              dataIndex: 'product_number',
              width: 90
            },{
              header: '规格',
              dataIndex: 'spec',
              width: 50
            },{
              header: '数量',
              dataIndex: 'quantity',
              align: 'right',
              width: 50
            },{
              header: '单价',
              dataIndex: 'unit_price',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.0000000000'),
              width: 110
            },{
              header: '总价',
              dataIndex: 'amount',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 80
            },{
              header: '进项税',
              dataIndex: 'value_added_tax',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 85
            },{
              header: '单价(含税)',
              dataIndex: 'tax_price',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 80
            },{
              header: '总价(含税)',
              dataIndex: 'tax_amount',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 85
            },{
              header: '套装或单品',
              dataIndex: 'is_suit',
              width: 70
            },{
              header: '采购入库差比',
              dataIndex: 'balance_quantity',
              align: 'right',
              width: 100
            },{
              header: '备注',
              dataIndex: 'description',
              width: 150
            }
          ]});
        //生成要订单的产品的Grid
        var purchaseOrderDetailGrid = new Ext.grid.GridPanel({
          title:'订单详细列表',
          store: purchaseOrderDetailDS,
          cm: purchaseOrderDetailCM,
          sm: purchaseOrderDetailSM,
          loadMask: true,
          width: screenWidth-175,
          height: 275,
          frame: true
        });

        //总的panel
        var workbenchPanel = new Ext.Panel({
          width: screenWidth-175,
          height: 735,
          frame:false,
          layout:'table',
          layoutConfig: {columns:1},
          defaults:{margins:'5 5 5 5'},
          items:[queryFormPanel,purchaseOrderGrid,purchaseOrderDetailGrid]
        });
        workbenchPanel.render("workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="workbench_panel"></div>
  </body>
</html>